package com.liang.controller;


import com.liang.empty.Result;
import com.liang.mapper.CoordinateDAO;
import com.liang.pojo.Coordinate;
import com.liang.service.CoordinateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

;

/**
 *@作者:lsk
 *Controller接口
 *@Date:2023/10/25
*/
@RestController
@RequestMapping("/CoordinateURL")
public class CoordinateController {


	@Autowired
	private CoordinateService coordinateservice;

	@Resource
	private CoordinateDAO coordinateDAO;


	/**
	根据Map_id查询
	*/
	@GetMapping("/selectByMap_id/{map_id}")
	public Result selectByMap_id(@PathVariable(value = "map_id") Long map_id){
		return Result.buildMessage(coordinateservice.selectByMap_id(map_id),"查询成功",200);
	}


	/**
	根据Map_id更新
	*/
	@PostMapping("/updateByMap_id")
	public Result updateByMap_id(@RequestBody Coordinate demo){
		return Result.buildMessage(coordinateservice.updateByMap_id( demo),"修改成功",0);
	}



	/**
	根据Map_id删除
	*/
	@GetMapping("/deleteByMap_id/{map_id}")
	public Result deleteByMap_id(@PathVariable(value = "map_id") Long map_id){
		return Result.buildMessage(coordinateservice.deleteByMap_id(map_id),"删除成功",0);
	}





	/**
	 insert:(插入)
	*/
	@PostMapping("/insert")
	public Result insert(@RequestBody Coordinate demo){
		Result.buildSuccess(coordinateservice.insert(demo));
		return Result.buildMessage(demo,"添加成功",0);
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	@PostMapping("/insertOrUpdate")
	public Result insertOrUpdate(@RequestBody Coordinate demo){
		return Result.buildMessage(coordinateservice.insertOrUpdate(demo),"插入或更新成功",200);
	}



	/**
	 insertBath:(批量插入)
	*/
	@PostMapping("/insertBatch")
	public Result insertBatch(@RequestBody List<Coordinate> list){
		return Result.buildMessage(coordinateservice.insertBatch(list),"批量插入成功",200);
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
	@PostMapping("/insertOrUpdateBatch")
	public Result insertOrUpdateBatch(@RequestBody List<Coordinate> list){
		return Result.buildMessage(coordinateservice.insertOrUpdateBatch(list),"批量更新成功",200);
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	@PostMapping("/selectList")
	public Result selectList(@RequestBody Map<String,Object> param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",coordinateservice.selectCount(param));
		}
		map.put("data",coordinateservice.selectList(param));
		return Result.buildMessage(map,"查询成功",200);
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
	@PostMapping("/selectCount")
	public Result selectCount(@RequestBody Map<String,Object> param){
		return Result.buildMessage(coordinateservice.selectCount(param),"查询数量成功",200);
	}


	/**
	 selectCount:(根据army_id删除)
	 */
	@PostMapping("/deleteByArmyID")
	public Result deleteByArmyID(@RequestBody Map<String,Object> param){
		return Result.buildMessage(coordinateDAO.deleteByArmyID(param),"查询数量成功",200);
	}



}